package com.easyvalid.cn.bean;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import com.easyvalid.cn.annotation.Valid;
import com.easyvalid.cn.basevalid.IValid;
import com.easyvalid.cn.util.ValidExceptionManager;

/**
 * 
 * <p>
 * Description: 待验证属性的get方法和验证信息的封装
 * </p>
 * 
 * @author xiaoruihu
 * @date 2015-3-20 下午07:02:35
 */
public class FieldAndIValid {
	/**
	 * 待验证属性的get方法
	 */
	private Method getMethod;
	/**
	 * 属性的验证接口
	 */
	private IValid ivalid;
	/**
	 * 属性的验证顺序
	 */
	private int order;

	public FieldAndIValid(Class<?> clazz, Field field, IValid ivalid, Valid valid) {
		this.ivalid = ivalid;

		try {
			PropertyDescriptor pd = new PropertyDescriptor(field.getName(), clazz);
			this.getMethod = pd.getReadMethod();
		} catch (Exception e) {
			ValidExceptionManager
					.ValidAnalyzeValidException("获取get方法失败，class " + clazz.getName() + " 属性 ： " + field.getName(), e);
		}
		this.order = valid.order();
	}

	public IValid getIvalid() {
		return ivalid;
	}

	public Method getGetMethod() {
		return getMethod;
	}

	public int getOrder() {
		return order;
	}

}
